import { createI18n } from 'vue-i18n'
import ls from '@/utils/Storage'
import { genLangs } from '@/utils/batchImportFiles'
const includePath = ['locales', 'pages', 'components']
let en = import.meta.globEager('/src/**/en.ts')
let cn = import.meta.globEager('/src/**/cn.ts')
en = genLangs(en, includePath)
cn = genLangs(cn, includePath)

const i18n = createI18n({
  locale: ls.get('lang') || 'zh-CN',
  legacy: false,
  globalInjection: true,
  messages: {
    'zh-CN': cn,
    'en-US': en
  }
})

export default i18n

export const getLocale = () => {
  return i18n.global.locale
}
